<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>

</head>

<body>
  <div id="app">
    <button @click="isShow=!isShow">{{isShow?'隐藏':'显示'}}</button>
    <common-head v-if="isShow"></common-head>
  </div>
  <script src="./vue.global.js"></script>
  <script>
    const { createApp } = Vue;
    const app = createApp({
      data(){
        return {
          isShow: true
        }
      }
    });
    const CommonHead = {
      // 模板视图
      template: `
        <div>
          这是组件
        </div>
      `,
      mounted () {
        console.log('组件初始化完成');
      },
      beforeUnmount() {
        console.log('卸载之前')
      },
    }
    app.component('CommonHead', CommonHead)

    app.mount('#app')
  </script>
</body>

</html>